#ifndef CHAT_SESSION_H
#define CHAT_SESSION_H

#include <iostream>
#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/enable_shared_from_this.hpp>

#include "GameMessage.h"
#include "GameRoom.h"
#include "Connection.h"
#include <Player.h>

using boost::asio::ip::tcp;

class GameServer;


class GameSession
        : public boost::enable_shared_from_this<GameSession>
{
public:
        ~GameSession();

        static chat_session_ptr create(connection_ptr tcp_connection, chat_room_ptr room)
	{
                chat_session_ptr session (new GameSession(tcp_connection, room));
		session->wait_for_data();
		return session;
	}

        void	deliver			(const GameMessage& msg);
        Player get_login           ();

private:
        GameSession(connection_ptr TCPConnection, chat_room_ptr room);
	void	wait_for_data	(); 

	void	handle_write	(const boost::system::error_code& error);
	void	handle_read		(const boost::system::error_code& error);

	connection_ptr				m_tcp_connection;
	chat_room_wptr				m_room;
        std::list<GameMessage>	m_write_events;
        GameMessage				m_message;
        Player         m_player_name;

	bool						is_leaving;
        bool        is_logged_in;
};

typedef boost::shared_ptr<GameSession> chat_session_ptr;



#endif
